package com.joshluisaac.jacksonlearning;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class MapToJson {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		ObjectMapper mapper = new ObjectMapper();

		Map<String, Object> map = new HashMap<String, Object>();

		map.put("email", "joshua@profitera.com");
		map.put("country", "Nigeria");
		map.put("residence", "Malaysia");
		map.put("mobile", "+6014731XXXX");

		List<String> employmentHistory = new ArrayList<String>();
		employmentHistory.add("Diagnostic Associates");
		employmentHistory.add("Oak Faith Pharma");
		employmentHistory.add("Clement-Isah & Partners");
		employmentHistory.add("Profitera Corp.");
		map.put("workExperience", employmentHistory);

		List<String> functionalLanguages = new ArrayList<String>();
		functionalLanguages.add("Erlang");
		functionalLanguages.add("Haskell");
		functionalLanguages.add("Scala");
		functionalLanguages.add("Closure");
		functionalLanguages.add("Lisp");

		List<String> objectOriented = new ArrayList<String>();
		objectOriented.add("C++");
		objectOriented.add("Java");
		objectOriented.add("C#");
		objectOriented.add("PHP");
		objectOriented.add("Python");
		objectOriented.add("Ruby");

		List<String> scripted = new ArrayList<String>();
		scripted.add("PHP");
		scripted.add("Python");
		scripted.add("Ruby");

		Map<String, Object> programmingLanguagesMap = new HashMap<String, Object>();
		programmingLanguagesMap.put("functional", functionalLanguages);
		programmingLanguagesMap.put("objectOriented", objectOriented);
		programmingLanguagesMap.put("scripted", scripted);

		map.put("languageTypes", programmingLanguagesMap);

		try {
			mapper.defaultPrettyPrintingWriter().writeValue(
					new File("mapToJson.json"), map);
			System.out.println(mapper.defaultPrettyPrintingWriter()
					.writeValueAsString(map));
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
